#include <stdio.h>
#include <string.h>

#define PASSWORD_SIZE 100
#define PASSWORD "myGOOGDpassword\n"

int main()
{
    int count = 0;
    char buff[PASSWORD_SIZE];

    for (; ;) {
        printf("Enter password:");
        fgets(&buff[0], PASSWORD_SIZE, stdin);

        if (strcmp(&buff[0], PASSWORD))
            printf("Wrong password\n");
        else 
            break;

        if (++count > 3) 
            return -1;
    }

    printf("Password OK\n");

    return 0;
}

#if 0

/*
 * intel
 */
00000000000011c9 <main>:
    11c9:	f3 0f 1e fa          	endbr64 
    11cd:	55                   	push   %rbp
    11ce:	48 89 e5             	mov    %rsp,%rbp
    11d1:	48 83 c4 80          	add    $0xffffffffffffff80,%rsp
    11d5:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    11dc:	00 00 
    11de:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    11e2:	31 c0                	xor    %eax,%eax
    11e4:	c7 45 8c 00 00 00 00 	movl   $0x0,-0x74(%rbp)
    11eb:	48 8d 3d 12 0e 00 00 	lea    0xe12(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    11f2:	b8 00 00 00 00       	mov    $0x0,%eax
    11f7:	e8 b4 fe ff ff       	callq  10b0 <printf@plt>
    11fc:	48 8b 15 0d 2e 00 00 	mov    0x2e0d(%rip),%rdx        # 4010 <stdin@@GLIBC_2.2.5>
    1203:	48 8d 45 90          	lea    -0x70(%rbp),%rax
    1207:	be 64 00 00 00       	mov    $0x64,%esi
    120c:	48 89 c7             	mov    %rax,%rdi
    120f:	e8 ac fe ff ff       	callq  10c0 <fgets@plt>
    1214:	48 8d 45 90          	lea    -0x70(%rbp),%rax
    1218:	48 8d 35 f5 0d 00 00 	lea    0xdf5(%rip),%rsi        # 2014 <_IO_stdin_used+0x14>
    121f:	48 89 c7             	mov    %rax,%rdi
    1222:	e8 a9 fe ff ff       	callq  10d0 <strcmp@plt>
    1227:	85 c0                	test   %eax,%eax
    1229:	74 1d                	je     1248 <main+0x7f>
    122b:	48 8d 3d f3 0d 00 00 	lea    0xdf3(%rip),%rdi        # 2025 <_IO_stdin_used+0x25>
    1232:	e8 59 fe ff ff       	callq  1090 <puts@plt>
    1237:	83 45 8c 01          	addl   $0x1,-0x74(%rbp)
    123b:	83 7d 8c 03          	cmpl   $0x3,-0x74(%rbp)
    123f:	7e aa                	jle    11eb <main+0x22>
    1241:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
    1246:	eb 12                	jmp    125a <main+0x91>
    1248:	90                   	nop
    1249:	48 8d 3d e4 0d 00 00 	lea    0xde4(%rip),%rdi        # 2034 <_IO_stdin_used+0x34>
    1250:	e8 3b fe ff ff       	callq  1090 <puts@plt>
    1255:	b8 00 00 00 00       	mov    $0x0,%eax
    125a:	48 8b 4d f8          	mov    -0x8(%rbp),%rcx
    125e:	64 48 33 0c 25 28 00 	xor    %fs:0x28,%rcx
    1265:	00 00 
    1267:	74 05                	je     126e <main+0xa5>
    1269:	e8 32 fe ff ff       	callq  10a0 <__stack_chk_fail@plt>
    126e:	c9                   	leaveq 
    126f:	c3                   	retq   

/*
 * arm
 */
000000000040067c <main>:
  40067c:	a9b87bfd 	stp	x29, x30, [sp, #-128]!
  400680:	910003fd 	mov	x29, sp
  400684:	b9007fbf 	str	wzr, [x29, #124]
  400688:	90000000 	adrp	x0, 400000 <_init-0x4d8>
  40068c:	911f0000 	add	x0, x0, #0x7c0
  400690:	97ffffb4 	bl	400560 <printf@plt>
  400694:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400698:	91012000 	add	x0, x0, #0x48
  40069c:	f9400001 	ldr	x1, [x0]
  4006a0:	910063a0 	add	x0, x29, #0x18
  4006a4:	aa0103e2 	mov	x2, x1
  4006a8:	52800c81 	mov	w1, #0x64                  	// #100
  4006ac:	97ffffb1 	bl	400570 <fgets@plt>
  4006b0:	90000000 	adrp	x0, 400000 <_init-0x4d8>
  4006b4:	911f4001 	add	x1, x0, #0x7d0
  4006b8:	910063a0 	add	x0, x29, #0x18
  4006bc:	97ffffa5 	bl	400550 <strcmp@plt>
  4006c0:	7100001f 	cmp	w0, #0x0
  4006c4:	54000180 	b.eq	4006f4 <main+0x78>  // b.none
  4006c8:	90000000 	adrp	x0, 400000 <_init-0x4d8>
  4006cc:	911fa000 	add	x0, x0, #0x7e8
  4006d0:	97ffff9c 	bl	400540 <puts@plt>
  4006d4:	b9407fa0 	ldr	w0, [x29, #124]
  4006d8:	11000400 	add	w0, w0, #0x1
  4006dc:	b9007fa0 	str	w0, [x29, #124]
  4006e0:	b9407fa0 	ldr	w0, [x29, #124]
  4006e4:	71000c1f 	cmp	w0, #0x3
  4006e8:	54fffd0d 	b.le	400688 <main+0xc>
  4006ec:	12800000 	mov	w0, #0xffffffff            	// #-1
  4006f0:	14000006 	b	400708 <main+0x8c>
  4006f4:	d503201f 	nop
  4006f8:	90000000 	adrp	x0, 400000 <_init-0x4d8>
  4006fc:	911fe000 	add	x0, x0, #0x7f8
  400700:	97ffff90 	bl	400540 <puts@plt>
  400704:	52800000 	mov	w0, #0x0                   	// #0
  400708:	a8c87bfd 	ldp	x29, x30, [sp], #128
  40070c:	d65f03c0 	ret


/*
 * arm32
 */
int main()
{
   10574:	e92d4800 	push	{fp, lr}			# fp, lr 入椎
   10578:	e28db004 	add	fp, sp, #4			# sp+4后存入fp
   1057c:	e24dd068 	sub	sp, sp, #104	; 0x68		# 开辟104个字节，一个int， 字符数组[100] 
    int count = 0;
   10580:	e3a03000 	mov	r3, #0		# r3 = 0
   10584:	e50b3008 	str	r3, [fp, #-8]	# fp - 8 = count = 0
    char buff[PASSWORD_SIZE];

    for (; ;) {
        printf("Enter password:");
   10588:	e59f0084 	ldr	r0, [pc, #132]	; 10614 <main+0xa0>	# 载放变量的地址，作为printf的参数
   1058c:	ebffff8f 	bl	103d0 <printf@plt>			# 调用printf
        fgets(&buff[0], PASSWORD_SIZE, stdin);
   10590:	e59f3080 	ldr	r3, [pc, #128]	; 10618 <main+0xa4>	# 载入变量的地址， 即stdin
   10594:	e5932000 	ldr	r2, [r3]				# 刚载入变量的地址上的值存入r2 <--- stdin
   10598:	e24b306c 	sub	r3, fp, #108	; 0x6c			# 开辟buff地址,108 - 8 = 100 
   1059c:	e3a01064 	mov	r1, #100	; 0x64			# 长度
   105a0:	e1a00003 	mov	r0, r3					# buff地址
   105a4:	ebffff8c 	bl	103dc <fgets@plt>			# 调用fgets

        if (strcmp(&buff[0], PASSWORD))
   105a8:	e24b306c 	sub	r3, fp, #108	; 0x6c
   105ac:	e59f1068 	ldr	r1, [pc, #104]	; 1061c <main+0xa8>
   105b0:	e1a00003 	mov	r0, r3
   105b4:	ebffff97 	bl	10418 <strcmp@plt>
   105b8:	e1a03000 	mov	r3, r0
   105bc:	e3530000 	cmp	r3, #0
   105c0:	0a000008 	beq	105e8 <main+0x74>
            printf("Wrong password\n");
   105c4:	e59f0054 	ldr	r0, [pc, #84]	; 10620 <main+0xac>
   105c8:	ebffff86 	bl	103e8 <puts@plt>
        else 
            break;

        if (++count > 3) 
   105cc:	e51b3008 	ldr	r3, [fp, #-8]
   105d0:	e2833001 	add	r3, r3, #1
   105d4:	e50b3008 	str	r3, [fp, #-8]
   105d8:	e51b3008 	ldr	r3, [fp, #-8]
   105dc:	e3530003 	cmp	r3, #3
   105e0:	da000007 	ble	10604 <main+0x90>
   105e4:	ea000004 	b	105fc <main+0x88>
        fgets(&buff[0], PASSWORD_SIZE, stdin);

        if (strcmp(&buff[0], PASSWORD))
            printf("Wrong password\n");
        else 
            break;
   105e8:	e1a00000 	nop			; (mov r0, r0)

        if (++count > 3) 
            return -1;
    }

    printf("Password OK\n");
   105ec:	e59f0030 	ldr	r0, [pc, #48]	; 10624 <main+0xb0>
   105f0:	ebffff7c 	bl	103e8 <puts@plt>

    return 0;
   105f4:	e3a03000 	mov	r3, #0
   105f8:	ea000002 	b	10608 <main+0x94>
            printf("Wrong password\n");
        else 
            break;

        if (++count > 3) 
            return -1;
   105fc:	e3e03000 	mvn	r3, #0
   10600:	ea000000 	b	10608 <main+0x94>
    }
   10604:	eaffffdf 	b	10588 <main+0x14>

    printf("Password OK\n");

    return 0;
}
   10608:	e1a00003 	mov	r0, r3
   1060c:	e24bd004 	sub	sp, fp, #4
   10610:	e8bd8800 	pop	{fp, pc}
   10614:	00010638 	.word	0x00010638
   10618:	0002078c 	.word	0x0002078c
   1061c:	00010648 	.word	0x00010648
   10620:	0001065c 	.word	0x0001065c
   10624:	0001066c 	.word	0x0001066c

#endif
